home *** CD-ROM | disk | FTP | other *** search
/ Aminet 51 / Aminet 51 (2002)(GTI - Schatztruhe)[!][Oct 2002].iso / Aminet / dev / c / minigl.lha / MiniGL / include / mgl / context.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-05-09  |  11.5 KB  |  457 lines

  1. /*
  2.  * $Id: context.h,v 1.1.1.1 2000/04/07 19:44:51 tfrieden Exp $
  3.  *
  4.  * $Date: 2000/04/07 19:44:51 $
  5.  * $Revision: 1.1.1.1 $
  6.  *
  7.  * (C) 1999 by Hyperion
  8.  * All rights reserved
  9.  *
  10.  * This file is part of the MiniGL library project
  11.  * See the file Licence.txt for more details
  12.  *
  13.  */
  14.  
  15. #ifndef __CONTEXT_H
  16. #define __CONTEXT_H
  17.  
  18. #include "mgl/matrix.h"
  19. #include "mgl/config.h"
  20. #include "mgl/vertexbuffer.h"
  21.  
  22. #ifdef __VBCC__
  23. #pragma amiga-align
  24. #endif
  25.  
  26. #include <intuition/intuition.h>
  27.  
  28. #ifdef __PPC__
  29. #include <devices/timer.h>
  30. #endif
  31.  
  32.  
  33. #ifdef __PPC__
  34. typedef struct LockTimeHandle_s
  35. {
  36.     struct timeval StartTime;
  37. } LockTimeHandle;
  38.  
  39. #else
  40.  
  41. typedef struct LockTimeHandle_s
  42. {
  43.     ULONG s_hi, s_lo;
  44.     ULONG e_freq;
  45. } LockTimeHandle;
  46.  
  47. #endif
  48.  
  49.  
  50. #ifdef __VBCC__
  51. #pragma default-align
  52. #endif
  53.  
  54. typedef struct GLcontext_t * GLcontext;
  55.  
  56. struct GLcontext_t;
  57.  
  58. typedef void (*DrawFn)(struct GLcontext_t *);
  59.  
  60. typedef enum
  61. {
  62.     MGLKEY_F1, MGLKEY_F2, MGLKEY_F3, MGLKEY_F4, MGLKEY_F5, MGLKEY_F6, MGLKEY_F7, MGLKEY_F8,
  63.     MGLKEY_F9, MGLKEY_F10,
  64.     MGLKEY_CUP, MGLKEY_CDOWN, MGLKEY_CLEFT, MGLKEY_CRIGHT
  65. } MGLspecial;
  66.  
  67. typedef enum
  68. {
  69.     GLCS_TEXTURE = 0x01,
  70.     GLCS_COLOR   = 0x02,
  71.     GLCS_VERTEX  = 0x04,
  72.     GLCS_MASK    = 0x07,
  73. } ClientStates;
  74.  
  75. typedef void (*KeyHandlerFn)(char key);
  76. typedef void (*SpecialHandlerFn)(MGLspecial special_key);
  77. typedef void (*MouseHandlerFn)(GLint x, GLint y, GLbitfield buttons);
  78. typedef void (*IdleFn)(void);
  79.  
  80.  
  81. /*
  82. ArrayPointer and stride storage:
  83.  
  84. We define all pointers as UBYTE to avoid problems with badly aligned arrays.
  85. */
  86.  
  87. typedef struct MGLAPointer_s
  88. {
  89.     GLint        colorstride;
  90.     ULONG        colormode;    //w3d bitfield
  91.     GLubyte        *colors;    //application array
  92.  
  93.     GLint        texcoordstride;
  94.     GLint        w_off;        //relative w-offset
  95.     GLubyte        *texcoords;    //application array
  96.  
  97.     GLint        vertexstride;
  98.     ULONG        vertexmode;    // fff / ddd / ffd
  99.     GLubyte        *verts;        //application array
  100.  
  101.     GLboolean    transformed;
  102.     GLuint        lockfirst;    
  103.     GLsizei        locksize;    //0 = unlocked
  104.  
  105.     GLboolean    FixpointTrans;
  106.  
  107. } MGLAPointer;
  108.  
  109.  
  110. typedef struct GLarray_t
  111. {
  112.     /*
  113.     ** Vertex array
  114.     */
  115.  
  116.     GLint       size;           /* Number of elements per entry (mostly 3 or 4) */
  117.     GLenum      type;           /* Data type of entries */
  118.     GLsizei     stride;         /* How to reach the next array element */
  119.     GLvoid*     pointer;        /* Pointer to the actual data */
  120. } GLarray;
  121.  
  122. #if 0
  123. typedef void (*DrawElementsFn)(GLcontext context, GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
  124. typedef void (*DrawArraysFn)(GLcontext context, GLenum mode, GLint first, GLsizei count);
  125. #endif
  126.  
  127. struct GLcontext_t
  128. {
  129.     /*
  130.     ** The primitive with which glBegin was called,
  131.     ** or GL_BASE if outside glBegin/glEnd
  132.     */
  133.  
  134.     GLenum      CurrentPrimitive;
  135.  
  136.     /*
  137.     ** Current error
  138.     */
  139.     GLenum      CurrentError;
  140.  
  141.     /*
  142.     ** The ModelView/Projection matrix stack.
  143.     ** Note that the topmost (= current) matrix is not the
  144.     ** top of the stack, but rather one of the ModelView[]/Projection[] below.
  145.     ** This makes copying the matrices unnecessary...
  146.     */
  147.     int         ModelViewStackPointer;
  148.     Matrix      ModelViewStack[MODELVIEW_STACK_SIZE];
  149.  
  150.     int         ProjectionStackPointer;
  151.     Matrix      ProjectionStack[PROJECTION_STACK_SIZE];
  152.  
  153.     /*
  154.     ** The current ModelView/Projeciton matrix.
  155.     ** The matrix multiplication routine will switch between those
  156.     ** two to avoid copying stuff.
  157.     */
  158.     GLuint      ModelViewNr;
  159.     Matrix      ModelView[2];
  160.  
  161.     #define     CurrentMV (&(context->ModelView[context->ModelViewNr]))
  162.     #define     SwitchMV  context->ModelViewNr = !(context->ModelViewNr)
  163.  
  164.     GLuint      ProjectionNr;
  165.     Matrix      Projection[2];
  166.  
  167.     #define     CurrentP (&(context->Projection[context->ProjectionNr]))
  168.     #define     SwitchP  context->ProjectionNr = !(context->ProjectionNr)
  169.  
  170.     // The current matrix mode (GL_MODELVIEW or GL_PROJECTION)
  171.     GLuint      CurrentMatrixMode;
  172.  
  173.  
  174.     /*
  175.     ** flexible buffer reserved for vertexarrays
  176.     */
  177.  
  178.     GLfloat   * WBuffer;
  179.  
  180.     UWORD     * ElementIndex; //for glArrayElement and index conversion in glDrawElements
  181.  
  182.     /*
  183.     ** Vertex buffers
  184.     ** A call to glVertex*() will fill one entry of the vertex buffer
  185.     ** with the current data. glEnd() will go over this data and
  186.     ** draw the primitives based on this.
  187.     */
  188.  
  189.     MGLVertex * VertexBuffer;
  190.     GLuint      VertexBufferPointer;        // Next free entry
  191.     GLuint      VertexBufferSize;           // Size of the buffer
  192.  
  193.     /*
  194.     ** Surgeon: Normals are only used in auto-texcoord generation and are not part of the W3D_Vertex struct used for drawing.
  195.     ** Besides, Normals are more often specified for a surface rather than for single verts.
  196.     ** The solution is a normal-buffer with position in the buffer recorded in glVertex*() functions.
  197.     ** With propewr implementation I believe this should generate a lot of cache hits in v_GenTexCoords :)
  198.     **
  199.     ** Note: CurrentNormal is now unused
  200.     **
  201.     **
  202.     ** A similar approach for colors is worth considering
  203.     ** (see vertexbuffer.h for a suggestion)
  204.     ** ubyte colors could be kept in that format until further down the pipeline.
  205.     ** If colors were stored in a buffer, the check for shademodel currently within glVertex could be delayed until after on/off-screen culling.
  206.     ** With smoothshading enabled, colorcopy and optional conversion from ubyte to float should probably be delayed until after the backface tests.
  207.     **
  208.     */
  209.  
  210.     MGLNormal * NormalBuffer;
  211.     GLuint        NormalBufferPointer;
  212.  
  213.     /*
  214.     ** Current colors
  215.     */
  216.     GLuint      ClearColor;
  217.     W3D_Double  ClearDepth;
  218.     W3D_Color   CurrentColor; //was MGLColor
  219.  
  220.  //Surgeon: minimize W3D_SetCurrentColor calls
  221.     GLboolean   UpdateCurrentColor;
  222.  
  223. #if 0 //exchanged for normalbuffer approach - Surgeon
  224.     MGLNormal   CurrentNormal;
  225. #endif
  226.  
  227.     GLfloat     CurrentTexS, CurrentTexT, CurrentTexQ;
  228.     GLboolean   CurrentTexQValid;
  229.     /*
  230.     ** The flag indicates wether the combined matrix is valid or not.
  231.     ** If it indicates GL_TRUE, the CombinedMatrix field contains the
  232.     ** product of the ModelView and Projection matrix.
  233.     */
  234.     GLboolean   CombinedValid;
  235.     Matrix      CombinedMatrix;
  236.  
  237.     /*
  238.     ** Scale factors for the transformation of normalized coordinates
  239.     ** to window coordinates. The *x and *y values are set by glViewPort.
  240.     ** *z is set by glDepthRange, which also sets near and far.
  241.     */
  242.  
  243. //    GLdouble    sx,sy,sz;
  244. //    GLdouble    ax,ay,az;
  245. #if 0 //surgeon: double precision not needed
  246.     GLdouble    sx,ax;
  247.     GLdouble    sy,ay;
  248.     GLdouble    sz,az;
  249. #else
  250.     GLfloat    sx,ax;
  251.     GLfloat    sy,ay;
  252.     GLfloat    sz,az;
  253. #endif
  254.     GLdouble    near,far;
  255.  
  256.     GLuint        ClipFlags;    //surgeon: viewport flags used with guardband clipping
  257.     GLboolean    GuardBand;    //surgeon
  258.  
  259.     // CullFace mode
  260.     GLenum      CurrentCullFace;
  261.     GLenum      CurrentFrontFace;
  262.  
  263.     // Sign extracted from above
  264.     //  0 means no culling
  265.     //  1 means back + ccw or front + cw
  266.     // -1 means back + cw  or front + ccw
  267.  
  268.     GLint        CurrentCullSign;    
  269.  
  270.     // Pixel states
  271.     GLint       PackAlign;
  272.     GLint       UnpackAlign;
  273.  
  274.     /*
  275.     ** GL Rendering States
  276.     */
  277.     GLboolean   AlphaTest_State;
  278.     GLboolean   Blend_State;
  279.     GLboolean   Texture2D_State[MAX_TEXUNIT];
  280.     GLboolean   TextureGenS_State;
  281.     GLboolean   TextureGenT_State;
  282.     GLboolean   Fog_State;
  283.     GLboolean   Scissor_State;
  284.     GLboolean   CullFace_State;
  285.     GLboolean   DepthTest_State;
  286.     GLboolean   PointSmooth_State;
  287.     GLboolean   Dither_State;
  288.     GLboolean   ZOffset_State;
  289.  
  290.     /*
  291.     ** 'Internal' states
  292.     */
  293.  
  294.     GLboolean   FogDirty;
  295.  
  296.     GLdouble    FogStart;
  297.     GLdouble    FogEnd;
  298.  
  299.     /*
  300.     ** Drawing and clipping functions for the current primitive
  301.     */
  302.  
  303.     DrawFn      CurrentDraw;
  304.  
  305.     /*
  306.     ** Warp3D specific stuff
  307.     */
  308.  
  309.     W3D_Context *           w3dContext;
  310.     struct Window *         w3dWindow;
  311.     struct Screen *         w3dScreen;
  312.  
  313.     GLboolean        ArrayTexBound;
  314.  
  315.     GLint                   CurrentBinding;
  316.  
  317.     //Multitexture
  318.     GLint                   VirtualBinding;
  319.     GLuint            VirtualTexUnits; //Surgeon
  320.     GLuint                ActiveTexture; //THF
  321.  
  322.     W3D_Texture **          w3dTexBuffer;
  323.     GLubyte **              w3dTexMemory;
  324.     GLint                   TexBufferSize;
  325.     struct ScreenBuffer *   Buffers[3];
  326.     struct BitMap *         w3dBitMap; // If in windowed mode
  327.     struct RastPort *       w3dRastPort; // for windowed ClipBlit mode
  328.     int                     BufNr;
  329.     int                     NumBuffers;
  330.     W3D_Scissor             scissor;
  331.     GLboolean               w3dLocked;
  332.  
  333. #ifdef AUTOMATIC_LOCKING_ENABLE
  334.     GLenum                  LockMode;
  335.     LockTimeHandle          LockTime;
  336. #endif
  337.     GLboolean               DoSync;
  338.     ULONG                   w3dChipID;
  339.     ULONG                   w3dFormat;
  340.     ULONG                   w3dAlphaFormat;
  341.     GLint                   w3dBytesPerTexel;
  342.  
  343.     GLenum                  TexEnv[MAX_TEXUNIT];
  344.     GLenum                  CurTexEnv;
  345.     GLenum                  MinFilter;
  346.     GLenum                  MagFilter;
  347.     GLenum                  WrapS;
  348.     GLenum                  WrapT;
  349.  
  350.     W3D_Fog                 w3dFog;
  351.     ULONG                   w3dFogMode;
  352.     GLfloat                 FogRange;
  353.     GLfloat                 FogMult;
  354.     GLenum                  ShadeModel;
  355.     GLboolean               DepthMask;
  356.  
  357.     GLboolean               NoMipMapping;
  358.     GLboolean               NoFallbackAlpha;
  359.  
  360.     KeyHandlerFn            KeyHandler;
  361.     MouseHandlerFn          MouseHandler;
  362.     SpecialHandlerFn        SpecialHandler;
  363.     IdleFn                  Idle;
  364.     GLboolean               Running;
  365.  
  366.     GLenum              SrcAlpha;
  367.     GLenum              DstAlpha;
  368.     GLboolean               AlphaFellBack;
  369.  
  370.     GLfloat                 InvRot[9];
  371.  
  372.     GLboolean       InvRotValid;
  373.     GLboolean       WOne_Hint;
  374.     GLboolean       FixpointTrans_Hint; //Surgeon
  375.  
  376.     GLfloat         ZOffset;
  377.  
  378.     void           *PaletteData;
  379.     GLenum          PaletteFormat;
  380.     GLint           PaletteSize;
  381.  
  382. /* Begin Joe Sera Sept. 23 2000 */
  383.     /*
  384.     ** GL Current Modes and States for glGetIntegerv
  385.     */
  386.     GLint CurPolygonMode ;      /* GL_POLYGON_MODE       */
  387.     GLint CurShadeModel ;       /* GL_SHADE_MODEL        */
  388.     GLint CurBlendSrc ;         /* GL_BLEND_SRC          */
  389.     GLint CurBlendDst ;         /* GL_BLEND_DST          */
  390.     GLint CurUnpackRowLength ;  /* GL_UNPACK_ROW_LENGTH  */
  391.     GLint CurUnpackSkipPixels ; /* GL_UNPACK_SKIP_PIXELS */
  392.     GLint CurUnpackSkipRows ;   /* GL_UNPACK_SKIP_ROWS   */
  393.  
  394. /* End Joe Sera Sept. 23 2000 */
  395.  
  396. /* Begin Joe Sera Oct. 21, 2000  */
  397.     /*
  398.     ** GL Current Modes and States for glGetBooleanv
  399.     */
  400.  
  401.     GLboolean CurWriteMask ;    /* GL_DEPTH_WRITE_MASK   */
  402.     GLboolean CurDepthTest ;    /* GL_DEPTH_TEST         */
  403.  
  404.  
  405. /* End Joe Sera Oct. 21 2000 */
  406.  
  407.     /*
  408.     ** Client state
  409.     */
  410.  
  411.     GLbitfield      ClientState;        /* Current client state mask */
  412.  
  413. #if 0
  414.  
  415.     GLarray         ColorArray;         /* Current arrays */
  416.     GLarray         TexCoordArray;
  417.     GLarray         VertexArray;
  418. #endif
  419.  
  420.     MGLAPointer    ArrayPointer;
  421.     GLboolean    VertexArrayPipeline;
  422.  
  423. #if 0
  424.     DrawElementsFn  DrawElementsHook;   /* Function pointers. These will depend on the state */
  425.     DrawArraysFn    DrawArraysHook;
  426. #endif
  427.  
  428.     GLfloat         MinTriArea;         /* Minimal area of triangles to be drawn (smaller ones will be rejected)*/
  429.  
  430.     GLfloat         CurrentPointSize;   /* diameter */
  431.  
  432.     GLubyte*        GeneratedTextures;  /* Array to keep track of generated textures */
  433.  
  434. };
  435.  
  436.  
  437. /*
  438. ** The CMATRIX macro give the address of the currently
  439. ** active matrix, depending on the matrix mode.
  440. ** The OMATRIX macro gives the address of the secondary matrix
  441. ** The SMATRIX macro switches the active and backup matrix
  442. */
  443. #define CMATRIX(context) context->CurrentMatrixMode == GL_MODELVIEW ?\
  444.     (&(context->ModelView[context->ModelViewNr])):\
  445.     (&(context->Projection[context->ProjectionNr]))
  446.  
  447. #define OMATRIX(context) context->CurrentMatrixMode == GL_MODELVIEW ?\
  448.     (&(context->ModelView[!(context->ModelViewNr)])):\
  449.     (&(context->Projection[!(context->ProjectionNr)]))
  450.  
  451. #define SMATRIX(context) if (context->CurrentMatrixMode == GL_MODELVIEW)\
  452.     context->ModelViewNr = !(context->ModelViewNr);\
  453.    else context->ProjectionNr = !(context->ProjectionNr)
  454.  
  455. #endif
  456.  
  457.